/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        condition_variable_event_win.h
// Purpose:     
// Author:      syy
// Modified by: 
// Created:     2014/1/3 15:45
// RCS-ID:      
// Licence:     
/////////////////////////////////////////////////////////////////////////////
#ifndef PR_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_EVENT_WIN_H_
#define PR_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_EVENT_WIN_H_

#include <windows.h>

#include "condition_variable_wrapper.h"

namespace qb
{

	class ConditionVariableEventWin : public ConditionVariableWrapper
	{
	public:
		ConditionVariableEventWin();
		virtual ~ConditionVariableEventWin();

		void SleepCS(CriticalSectionWrapper& crit_sect);
		bool SleepCS(CriticalSectionWrapper& crit_sect, unsigned long max_time_inMS);
		void Wake();
		void WakeAll();

	private:
		enum EventWakeUpType
		{
			WAKEALL_0   = 0,
			WAKEALL_1   = 1,
			WAKE        = 2,
			EVENT_COUNT = 3
		};

		unsigned int     num_waiters_[2];
		EventWakeUpType  eventID_;
		CRITICAL_SECTION num_waiters_crit_sect_;
		HANDLE           events_[EVENT_COUNT];
	};

}  // namespace qb

#endif  // PR_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_EVENT_WIN_H_
